/**
 * 
 */
package com.hs.pre.model;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.hs.Environment;

/**
 * @author shl
 *
 */
public class PreEntry extends BaseEntry{
  private long preId = 0;//主键
  private String fangm = null;//方名
  private String biem = null;//别名
  private String chufly = null;//处方来源
  private String yaowzc = null;//药物组成
  private String jiaj = null;//加减
  private String gongx = null;//功效
  private String zhuz = null;//主治
  private String id = null;//编号
  private String zhibff = null;//制备方法
  private String yongfyl = null;//用法用量
  private String yongyjj = null;//用药禁忌
  private String lincyy = null;//临床应用
  private String yaolzy = null;//药理作用
  private String gejls = null;//各家论述
  private String beiz = null;//备注； 
  private String suoyinzt = null;//索引状态
  private String suoyinsj = null;//索引时间
  private Object params[] = null;
  private ArrayList fangjly = new ArrayList();
  private String fangjly1[] = null;
  private static Map PRE_TYPE = new HashMap();
  public static String INDEX_STATUS_ONE = "01";//未索引
  public static String INDEX_STATUS_TWO = "02";//已索引
  public static String PRE_STATUS_ONE = "0";//初始化数据
  public static String PRE_STATUS_TWO = "1";//未提交
  public static String PRE_STATUS_THREE = "2";//已提交
  private String submitFlag = "0";
  static {
	  PRE_TYPE.put("散", "散剂");
	  PRE_TYPE.put("饮", "饮剂");
	  PRE_TYPE.put("膏", "膏剂");
	  PRE_TYPE.put("汤", "汤剂");
  }
  
  /**
   * to get data from map and ensure the return data is not null
   * @author CaoMudan on 2008-10-26
   */
private String notNull(Map data,String key){
	if(data==null){
		return "";
	}
	if(data.get(key)==null){
		return "";
	}
	return data.get(key).toString();
}

/**
 * mod by CaoMudan on 2008-10-26
 */
public PreEntry(Map data){
	this.beiz = notNull(data,"beiz");
	this.gejls = notNull(data,"gejls");
	this.yaolzy = notNull(data,"yaolzy");
	this.lincyy = notNull(data,"lincyy");
	this.yongyjj = notNull(data,"yongyjj");
	this.yongfyl = notNull(data,"yongfyl"); 
	this.zhibff = notNull(data,"zhibff");
	this.id = notNull(data,"id");
	this.zhuz = notNull(data,"zuz");
	this.gongx = notNull(data,"gongx");
	this.jiaj = notNull(data,"jiaj");
	this.yaowzc = notNull(data,"yaowzc");
	this.chufly = notNull(data,"chufly");
	this.biem = notNull(data,"biem");
	this.fangm = notNull(data,"fangm");
	this.suoyinsj = notNull(data,"suoyinsj");
	this.suoyinzt = notNull(data,"suoyinzt"); 
	if(data.get("preId") != null)
		preId = (Long)data.get("preId");
	params = new Object[]{this.fangm,this.biem,this.chufly,this.yaowzc,this.jiaj,this.gongx,this.zhuz,this.id,this.zhibff,
			this.yongfyl,this.yongyjj,this.lincyy,this.yaolzy,this.gejls,this.beiz};
	
//	if(null != data){
//		this.beiz = data.get("beiz")+"";
//		this.gejls = data.get("gejls")+"";
//		this.yaolzy = data.get("yaolzy")+"";
//		this.lincyy = data.get("lincyy")+"";
//		this.yongyjj = data.get("yongyjj")+"";
//		this.yongfyl = data.get("yongfyl")+"";
//		this.zhibff = data.get("zhibff")+"";
//		this.id = data.get("id")+"";
//		this.zhuz = data.get("zhuz")+"";
//		this.gongx = data.get("gongx")+"";
//		this.jiaj = data.get("jiaj")+"";
//		this.yaowzc = data.get("yaowzc")+"";
//		this.chufly = data.get("chufly")+"";
//		this.biem = data.get("biem")+"";
//		this.fangm = data.get("fangm")+""; 
//		this.suoyinsj = data.get("suoyinsj")+"";
//		this.suoyinzt = data.get("suoyinzt")+"";
//		if(data.get("preId") != null)
//		preId = (Long)data.get("preId");
//		params = new Object[]{this.fangm,this.biem,this.chufly,this.yaowzc,this.jiaj,this.gongx,this.zhuz,this.id,this.zhibff,
//				this.yongfyl,this.yongyjj,this.lincyy,this.yaolzy,this.gejls,this.beiz};
//	}
}
public PreEntry() {
	// TODO Auto-generated constructor stub
}
public long getPreId() {
	return preId;
}
public void setPreId(long preId) {
	this.preId = preId;
}
public String getFangm() {
	return fangm;
}
public void setFangm(String fangm) {
	this.fangm = fangm;
}
public String getBiem() {
	return biem;
}
public void setBiem(String biem) {
	this.biem = biem;
}
public String getChufly() {
	return chufly;
}
public void setChufly(String chufly) {
	this.chufly = chufly;
}
public String getYaowzc() {
	return yaowzc;
}
public void setYaowzc(String yaowzc) {
	this.yaowzc = yaowzc;
}
public String getJiaj() {
	return jiaj;
}
public void setJiaj(String jiaj) {
	this.jiaj = jiaj;
}
public String getGongx() {
	return gongx;
}
public void setGongx(String gongx) {
	this.gongx = gongx;
}
public String getZhuz() {
	return zhuz;
}
public void setZhuz(String zhuz) {
	this.zhuz = zhuz;
}
public String getId() {
	return id;
}
public void setId(String id) {
	this.id = id;
}
public String getZhibff() {
	return zhibff;
}
public void setZhibff(String zhibff) {
	this.zhibff = zhibff;
}
public String getYongfyl() {
	return yongfyl;
}
public void setYongfyl(String yongfyl) {
	this.yongfyl = yongfyl;
}
public String getYongyjj() {
	return yongyjj;
}
public void setYongyjj(String yongyjj) {
	this.yongyjj = yongyjj;
}
public String getLincyy() {
	return lincyy;
}
public void setLincyy(String lincyy) {
	this.lincyy = lincyy;
}
public String getYaolzy() {
	return yaolzy;
}
public void setYaolzy(String yaolzy) {
	this.yaolzy = yaolzy;
}
public String getGejls() {
	return gejls;
}
public void setGejls(String gejls) {
	this.gejls = gejls;
}
public String getBeiz() {
	return beiz;
}
public void setBeiz(String beiz) {
	this.beiz = beiz;
}
public Object[] getParams() {
	return params;
}
public void setParams(Object[] params) {
	this.params = params;
}
/**
 * 获得方剂来源
 * @return
 */
public List getFjly(){
	//System.out.println("fangjilaiyuan:" + this.chufly);
	if(null != this.chufly){
		String[] temp = this.chufly.split("》");
		if( null != temp && temp.length>0){
			for(int i=0;i<temp.length;i++){
				String tmp = temp[i];
				//System.out.println(tmp);
				if(tmp.indexOf("《") != -1){
					fangjly.add(tmp.substring(1).trim());
				} 
			}
		}
	}
	
	return this.fangjly;
}
/**
 * 获得方剂所属类别
 * @return
 */
public String getFangjlb(){
	String type = null;
	if(null != this.fangm){
	   if(this.fangm.length() > 1){
		   String tmp = this.fangm.substring(this.fangm.length()-1);
		   if(PRE_TYPE.get(tmp) != null)
			   type = (String)PRE_TYPE.get(tmp);
	   }
	}
	return type;
}
public static void main(String[] args){
	PreEntry p = new PreEntry();
	
	String temp = "《良方合璧》卷下。";
	p.setChufly(temp);
	
		System.out.println("ss:" + p.getFjly());
	 
	
}
public String getSuoyinzt() {
	if(INDEX_STATUS_ONE.equals(this.suoyinzt))
		return "未索引";
	else if(INDEX_STATUS_TWO.equals(this.suoyinzt))
		return "已索引";
	return "";
}
public void setSuoyinzt(String suoyinzt) {
	this.suoyinzt = suoyinzt;
}
public String getSuoyinsj() {
	return suoyinsj;
}
public void setSuoyinsj(String suoyinsj) {
	this.suoyinsj = suoyinsj;
}
public ArrayList getFangjly() {
	return fangjly;
}
public void setFangjly(ArrayList fangjly) {
	this.fangjly = fangjly;
}
public String[] getFangjly1() {
	return fangjly1;
}
public void setFangjly1(String[] fangjly1) {
	this.fangjly1 = fangjly1;
}
public static Map getPRE_TYPE() {
	return PRE_TYPE;
}
public static void setPRE_TYPE(Map pre_type) {
	PRE_TYPE = pre_type;
}
public void initJob(){
	JobEntry job = new JobEntry();
	job.setExeClass("com.hs.job.task.ExeIndexTask");
	job.setJobDesc("方剂数据索引");
	job.setJobType(JobEntry.JOB_TYPE_ONE);
	job.setRelationId(this.id);
	job.insertJob();
}

public String getSubmitFlag() {
	   this.submitFlag = PreEntry.PRE_STATUS_ONE;
	   if(!Environment.getVersion()){
		   submitFlag = PreEntry.PRE_STATUS_TWO;
	   }
	return submitFlag;
}
public static String getFlagByVersion() { 
	   if(!Environment.getVersion()){
		   return PreEntry.PRE_STATUS_TWO;
	   } 
		   return PreEntry.PRE_STATUS_ONE; 
}

public void setSubmitFlag(String submitFlag) {
	this.submitFlag = submitFlag;
}
} 
